<?php
	/**
	 * 	学生登录
	 * 		@return $student[sname,snumber,stuid,collegename,scollegeid,gradename,classname]
	 */
	function selectStuByPassAndNum($spass,$snumber){
		$conn = mysqli_connect("localhost:3306","mebin","171110301cwb","sms");
		$sql =	" select " .
				" 	sname,snumber,stuid,collegename,scollegeid,gradename,classname,sschool,ssex,ssys,senter,sgrad,sbirth,sidnumber,snative,sdesc " .
				" from " .
				" 	student_roll,grade,class,college " .
				" where " .
				" 	spass='$spass' and snumber='$snumber' " .
				"  	and student_roll.scollegeid = college.collegeid " .
				"  	and student_roll.sgradeid = grade.gradeid " .
				"  	and student_roll.sclassid = class.classid " ;
		$result = mysqli_query($conn, $sql);
		$student = null;
		if(mysqli_num_rows($result) == 1){
			$rows = mysqli_fetch_assoc($result);
			$student['sname'] = $rows['sname'];
			$student['snumber'] = $rows['snumber'];
			$student['stuid'] = $rows['stuid'];
			$student['collegename'] = $rows['collegename'];
			$student['scollegeid'] = $rows['scollegeid'];
			$student['gradename'] = $rows['gradename'];
			$student['classname'] = $rows['classname'];
			$student['sschool'] = $rows['sschool'];
			$student['ssex'] = $rows['ssex'];
			$student['ssys'] = $rows['ssys'];
			$student['senter'] = $rows['senter'];
			$student['sgrad'] = $rows['sgrad'];
			$student['sbirth'] = $rows['sbirth'];
			$student['sidnumber'] = $rows['sidnumber'];
			$student['snative'] = $rows['snative'];
			$student['sdesc'] = $rows['sdesc'];
		}	
		mysqli_close($conn);
		return $student;
	}
	
	
	/**
	 * 插入学生选课信息
	 */
	function insertStuSection($stusec){
		$conn = mysqli_connect("localhost:3306","mebin","171110301cwb","sms");
		$flag = true;
		$sql = "select stu_secid from student_section where stu_secid='{$stusec["stu_secid"]}' ";
		$result = mysqli_query($conn,$sql);
		if(mysqli_num_rows($result)){
			$rows = mysqli_fetch_assoc($result);
			$sql =  " update student_section set " .
					"    sections='{$stusec["sections"]}' " .
					" where stu_secid='{$stusec["stu_secid"]}' ";
			mysqli_query($conn,$sql);
			if(mysqli_errno($conn)){
				$flag = false;
				echo mysqli_error($conn);
			}
		}else{
			$sql = 	" insert into student_section " .
					" 	(sections,stu_secid) " .
					" values " .
					" 	('{$stusec["sections"]}','{$stusec["stu_secid"]}') " ;
			mysqli_query($conn,$sql);
			if(mysqli_errno($conn)){
				$flag = false;
				echo mysqli_error($conn);
			}
		}
		mysqli_close($conn);
		return $flag;
	}
	
	/**
	 *  查询学生成绩
	 */
	function selectStumark(){
		$conn = mysqli_connect("localhost:3306","mebin","171110301cwb","SMS");
		$sql =  " select mark_stuid,mark_tid,mark from mark order by mark_stuid";
		$result = mysqli_query($conn, $sql);
		$student_marks = [];
		while($rows = mysqli_fetch_assoc($result)){
			$student_marks[] = $rows;
		}
		mysqli_close($conn);
		return $student_marks;
	}
	
	/**
	 * 查询老师信息
	 */
	function selectSec_Tea($tid){
		$conn = mysqli_connect("localhost:3306","mebin","171110301cwb","SMS");
		$sql =  " select tname,tcourse,collegename,tattr " .
				"     from teacher t,college c " .
				" where t.tcollegeid=c.collegeid and t.tid = $tid ";
		$result = mysqli_query($conn, $sql);
		$teacher = null;
		if(mysqli_num_rows($result) == 1){
			$rows = mysqli_fetch_assoc($result);
			$teacher['tname'] = $rows['tname'];
			$teacher['tcourse'] = $rows['tcourse'];
			$teacher['collegename'] = $rows['collegename'];
			$teacher['tattr'] = $rows['tattr'];
		}
		mysqli_close($conn);
		return $teacher;
	}
?>